import Vue from 'vue'
import Vuex from 'vuex'
import routes from '@/router/Router-config'

Vue.use(Vuex)
export const vuex = new Vuex.Store({
    // strict: true,  //严格模式
    routes,
    state: {
        showshrink: false, //左菜单导航收缩
        overwidth: "calc(100% - 286px)", //tag滚动
        chatwidth: "calc(100% - 470px)", //聊天窗口大小
        currentMenu: null,
        tabsList: [{
            path: '/home',
            name: '首页',
            icon: 'iconfont iconhome'
        }],
        visitedViews: [],
    },
    getters: {
        // visitedViews: (state) => state.visitedViews
    },
    mutations: {
        showshrinkFunc(state, e) {
            state.showshrink = e;
            if (e == true) {
                state.overwidth = "calc(100% - 152px)";
                state.chatwidth = "calc(100% - 333px)";
            } else {
                state.overwidth = "calc(100% - 286px)";
                state.chatwidth = "calc(100% - 470px)";
            }


        },
        //选择标签 选择面包屑
        selectMenu(state, val) {
            if (val.path === '/home') {
                state.currentMenu = null
            } else {
                state.currentMenu = val
                    //如果等于-1说明tabsList不存在那么插入，否则什么都不做
                let result = state.tabsList.findIndex(item => item.path === val.path);
                result === -1 ? state.tabsList.push(val) : null

            }
            // val.path === '/home' ? (state.currentMenu = null) : (state.currentMenu = val)
        },
        //关闭标签
        closeTab(state, val) {

            let result = state.tabsList.findIndex(item => item.path === val.path)
            state.tabsList.splice(result, 1)
        },
        addVisitedView(state, payload) {
            if (state.visitedViews.some(item => item.path === payload.path)) return
            state.tabsList.push(
                Object.assign({}, payload, {
                    name: payload.name || '无效标签'
                })
            )
        },
    }

});